package com.timmy.google_play.fragment;

import android.support.annotation.NonNull;
import android.view.View;
import android.widget.ListView;

import com.timmy.google_play.base.BaseFragment;
import com.timmy.google_play.base.BaseHolder;
import com.timmy.google_play.base.ListViewFactory;
import com.timmy.google_play.base.LoadingPager;
import com.timmy.google_play.base.SuperBaseAdapter;
import com.timmy.google_play.bean.SubjectBean;
import com.timmy.google_play.holder.SubjectHolder;
import com.timmy.google_play.protocol.SubjectProtocol;

import java.util.List;

/**
 * Created by Timmy on 2016/12/7.
 */
public class SubjectFramgent extends BaseFragment {

    private SubjectProtocol   mProtocol;
    private List<SubjectBean> mDatas;

    @Override
    protected LoadingPager.LoadedResult initData() {

        mProtocol = new SubjectProtocol();
        try {
            mDatas = mProtocol.loadData(0);
            return checkResData(mDatas);

        } catch (Exception e) {
            e.printStackTrace();
            return LoadingPager.LoadedResult.ERROR;
        }
    }

    @Override
    protected View initSuccessView() {
        ListView listView = ListViewFactory.createListView();

        listView.setAdapter(new SubjectAdapter(listView, mDatas));

        return listView;
    }

    static class SubjectAdapter extends SuperBaseAdapter<SubjectBean> {

        public SubjectAdapter(ListView listView, List<SubjectBean> datas) {
            super(listView, datas);
        }

        @NonNull
        @Override
        protected BaseHolder<SubjectBean> getSpecialBaseHolder(int position) {
            return new SubjectHolder();
        }
    }
}

